package com.wanmait.teatrain.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.teatrain.entity.Course;
import com.wanmait.teatrain.mapper.CourseMapper;
import com.wanmait.teatrain.service.CourseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wanmait.teatrain.utils.AjaxResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 课程表 服务实现类
 * </p>
 *
 * @author wanmait
 * @since 2025-10-22
 */
@Service
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements CourseService {
    @Resource
    private CourseMapper courseMapper;

    @Override
    //查询已经上架的课程
    public AjaxResult selectAllCourse(Integer pageNum,String search,Boolean isStop) {
        PageHelper.startPage(pageNum,9);
        LambdaQueryWrapper<Course> courseLambdaQueryWrapper = new LambdaQueryWrapper<>();
        courseLambdaQueryWrapper.eq(isStop!=null,Course::getStop,isStop);
        courseLambdaQueryWrapper.like(search != null,Course::getCourseName,search);
        List<Course> courseList   = courseMapper.selectList(courseLambdaQueryWrapper);
        PageInfo<Course> pageInfo = new PageInfo<>(courseList);
        return AjaxResult.success().put("courses",pageInfo);
    }
}
